package com.tqjc.system.C24012.core.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tqjc.system.C24012.common.entity.SysFaultRecordInfoEntity;
import com.tqjc.system.C24012.common.entity.VO.FaultRecordInfoVO;
import com.tqjc.system.C24012.common.entity.VO.StatDataVO;
import com.tqjc.system.C24012.core.dao.SysFaultRecordInfoMapper;
import com.tqjc.system.C24012.core.service.SysFaultRecordInfoService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: 86195
 * @CreateTime: 2024-07-10  16:49
 * @Description: TODO
 * @Version: 1.0
 */
@Service
@Slf4j
public class SysFaultRecordInfoServiceImpl extends ServiceImpl<SysFaultRecordInfoMapper, SysFaultRecordInfoEntity> implements SysFaultRecordInfoService  {
    @Override
    public List<StatDataVO> getStatData(FaultRecordInfoVO alarmInfoVO) {
        return baseMapper.getStatData(alarmInfoVO);
    }

    @Override
    public IPage<SysFaultRecordInfoEntity> getListByPage(Page<SysFaultRecordInfoEntity> pageEntity, FaultRecordInfoVO alarmInfoVO) {
        LambdaQueryWrapper<SysFaultRecordInfoEntity> queryWrapper = new LambdaQueryWrapper<SysFaultRecordInfoEntity>()
                .eq(StringUtils.isNotEmpty(alarmInfoVO.getFaultType()), SysFaultRecordInfoEntity::getFaultType, alarmInfoVO.getFaultType())
                .le(alarmInfoVO.getHappenEndDate() != null, SysFaultRecordInfoEntity::getCreateDate, alarmInfoVO.getHappenEndDate())
                .ge(alarmInfoVO.getHappenStartDate() != null, SysFaultRecordInfoEntity::getCreateDate, alarmInfoVO.getHappenStartDate())
                .orderByDesc(SysFaultRecordInfoEntity::getCreateDate);
        return super.page(pageEntity,queryWrapper);
    }
}
